<?php

namespace app\bbxw\command;


use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
/**
 * 重置金额
 * Class SmsNum
 * @package app\common\command
 */
class ResetCustomer extends Command
{
    /**
     * 配置指令
     */
    protected function configure()
    {
        $this->setName('xbbxw:resetCustomer');
        $this->setDescription('ResetCustomer');
    }

    protected function execute(Input $input, Output $output)
    {
        $this->setQueueProgress("正在解析数据,请稍等...", 0);

        $count = 0;
        $prestore_amounts = $this->app->db->name("play_accompany")
            ->field("sum(prepaid_amount) as prestore_total_amount,customer_id,sum(business_amount) as use_total_amount")
            ->group('customer_id')->select()->toArray();
        $total = count($prestore_amounts);
        foreach ($prestore_amounts as $v){
            $this->app->db->name("customer")->where(['id'=>$v['customer_id']])
                ->update([
                    'use_total_amount'=>$v['use_total_amount'],
                    'prestore_total_amount'=>$v['prestore_total_amount']
                    ]);
            $this->queue->message($total, ++$count, "正在更新金额...");
        }


        $this->setQueueSuccess("数据更新成功,请刷新页面");
    }
}